
###############################
#### Adam Chilton          ####
#### Cristian Eyzaguirre   ####
#### David Landau	       ####
#### Mila Versteeg         ####
#### Constraining  		   #### 
#### Constitution-Making	   #### 
#### 11/27/2023            ####
###############################

######################################
####### Install & Load Libraries #####
######################################

# Note: These packages only need to be installed once.
 install.packages("mediation")
 install.packages("foreign")
 install.packages("rms")
 install.packages("sciplot")
 install.packages("Hmisc")
 install.packages("Zelig")
 install.packages("pwr")
 install.packages("epibasix")
 install.packages("RItools")
 install.packages("binscatter")
 install.packages("margins")


#Note: These packages need to be loaded before peforming the below analysis. 
library("foreign")
library("Hmisc")
library("rms")
library("mediation")
library("sciplot")
library("RItools")
library("Zelig")
library("pwr")
library("epibasix")
library("margins")

###############################
####### Load the Data #########
###############################

data <- read.csv("Data_ChileSurvey_220827.csv", sep=",", header=TRUE)
names(data)
head(data)
dim(data)


#####################################
####### Creating Variables  #########
#####################################


table(data$QD1)
table(data$QD2)

table(data$QE1)
table(data$QE2)

table(data$QF1)
table(data$QF2)


#### Flipping the Response Variable 

data$substance_binding[data$QD1==1]<-5
data$substance_binding[data$QD1==2]<- 4
data$substance_binding[data$QD1==3]<- 3
data$substance_binding[data$QD1==4]<- 2
data$substance_binding[data$QD1==5]<- 1

data$substance_good[data$QD2==1]<-5
data$substance_good[data$QD2==2]<- 4
data$substance_good[data$QD2==3]<- 3
data$substance_good[data$QD2==4]<- 2
data$substance_good[data$QD2==5]<- 1

data$procedure_binding[data$QE1==1]<-5
data$procedure_binding[data$QE1==2]<- 4
data$procedure_binding[data$QE1==3]<- 3
data$procedure_binding[data$QE1==4]<- 2
data$procedure_binding[data$QE1==5]<- 1

data$procedure_good[data$QE2==1]<-5
data$procedure_good[data$QE2==2]<- 4
data$procedure_good[data$QE2==3]<- 3
data$procedure_good[data$QE2==4]<- 2
data$procedure_good[data$QE2==5]<- 1

data$authority_binding[data$QF1==1]<-5
data$authority_binding[data$QF1==2]<- 4
data$authority_binding[data$QF1==3]<- 3
data$authority_binding[data$QF1==4]<- 2
data$authority_binding[data$QF1==5]<- 1

data$authority_good[data$QF2==1]<-5
data$authority_good[data$QF2==2]<- 4
data$authority_good[data$QF2==3]<- 3
data$authority_good[data$QF2==4]<- 2
data$authority_good[data$QF2==5]<- 1

data$substance_binding_binary[data$QD1==1]<-1
data$substance_binding_binary[data$QD1==2]<- 1
data$substance_binding_binary[data$QD1==3]<- 0
data$substance_binding_binary[data$QD1==4]<- 0
data$substance_binding_binary[data$QD1==5]<- 0

data$substance_good_binary[data$QD2==1]<-1
data$substance_good_binary[data$QD2==2]<- 1
data$substance_good_binary[data$QD2==3]<- 0
data$substance_good_binary[data$QD2==4]<- 0
data$substance_good_binary[data$QD2==5]<- 0

data$procedure_binding_binary[data$QE1==1]<-1
data$procedure_binding_binary[data$QE1==2]<- 1
data$procedure_binding_binary[data$QE1==3]<- 0
data$procedure_binding_binary[data$QE1==4]<- 0
data$procedure_binding_binary[data$QE1==5]<- 0

data$procedure_good_binary[data$QE2==1]<-1
data$procedure_good_binary[data$QE2==2]<- 1
data$procedure_good_binary[data$QE2==3]<- 0
data$procedure_good_binary[data$QE2==4]<- 0
data$procedure_good_binary[data$QE2==5]<- 0

data$authority_binding_binary[data$QF1==1]<-1
data$authority_binding_binary[data$QF1==2]<- 1
data$authority_binding_binary[data$QF1==3]<- 0
data$authority_binding_binary[data$QF1==4]<- 0
data$authority_binding_binary[data$QF1==5]<- 0

data$authority_good_binary[data$QF2==1]<-1
data$authority_good_binary[data$QF2==2]<- 1
data$authority_good_binary[data$QF2==3]<- 0
data$authority_good_binary[data$QF2==4]<- 0
data$authority_good_binary[data$QF2==5]<- 0


table(data$QE2)

454+1207

1216+810+257

1661/(1661+2283)


data$substance_strikedown[data$QG1==1]<-5
data$substance_strikedown[data$QG1==2]<- 4
data$substance_strikedown[data$QG1==3]<- 3
data$substance_strikedown[data$QG1==4]<- 2
data$substance_strikedown[data$QG1==5]<- 1

data$substance_strikedown_binary[data$QG1==1]<-5
data$substance_strikedown_binary[data$QG1==2]<- 4
data$substance_strikedown_binary[data$QG1==3]<- 3
data$substance_strikedown_binary[data$QG1==4]<- 2
data$substance_strikedown_binary[data$QG1==5]<- 1

data$substance_votedown[data$QG2==1]<-5
data$substance_votedown[data$QG2==2]<- 4
data$substance_votedown[data$QG2==3]<- 3
data$substance_votedown[data$QG2==4]<- 2
data$substance_votedown[data$QG2==5]<- 1

data$procedure_strikedown[data$QH1==1]<-5
data$procedure_strikedown[data$QH1==2]<- 4
data$procedure_strikedown[data$QH1==3]<- 3
data$procedure_strikedown[data$QH1==4]<- 2
data$procedure_strikedown[data$QH1==5]<- 1

data$procedure_votedown[data$QH2==1]<-5
data$procedure_votedown[data$QH2==2]<- 4
data$procedure_votedown[data$QH2==3]<- 3
data$procedure_votedown[data$QH2==4]<- 2
data$procedure_votedown[data$QH2==5]<- 1

data$authority_strikedown[data$QI1==1]<-5
data$authority_strikedown[data$QI1==2]<- 4
data$authority_strikedown[data$QI1==3]<- 3
data$authority_strikedown[data$QI1==4]<- 2
data$authority_strikedown[data$QI1==5]<- 1

data$authority_votedown[data$QI2==1]<-5
data$authority_votedown[data$QI2==2]<- 4
data$authority_votedown[data$QI2==3]<- 3
data$authority_votedown[data$QI2==4]<- 2
data$authority_votedown[data$QI2==5]<- 1



data$substance_strikedown_binary[data$QG1==1]<-1
data$substance_strikedown_binary[data$QG1==2]<- 1
data$substance_strikedown_binary[data$QG1==3]<- 0
data$substance_strikedown_binary[data$QG1==4]<- 0
data$substance_strikedown_binary[data$QG1==5]<- 0

data$substance_votedown_binary[data$QG2==1]<-1
data$substance_votedown_binary[data$QG2==2]<- 1
data$substance_votedown_binary[data$QG2==3]<- 0
data$substance_votedown_binary[data$QG2==4]<- 0
data$substance_votedown_binary[data$QG2==5]<- 0

data$procedure_strikedown_binary[data$QH1==1]<-1
data$procedure_strikedown_binary[data$QH1==2]<- 1
data$procedure_strikedown_binary[data$QH1==3]<- 0
data$procedure_strikedown_binary[data$QH1==4]<- 0
data$procedure_strikedown_binary[data$QH1==5]<- 0

data$procedure_votedown_binary[data$QH2==1]<-1
data$procedure_votedown_binary[data$QH2==2]<- 1
data$procedure_votedown_binary[data$QH2==3]<- 0
data$procedure_votedown_binary[data$QH2==4]<- 0
data$procedure_votedown_binary[data$QH2==5]<- 0

data$authority_strikedown_binary[data$QI1==1]<-1
data$authority_strikedown_binary[data$QI1==2]<- 1
data$authority_strikedown_binary[data$QI1==3]<- 0
data$authority_strikedown_binary[data$QI1==4]<- 0
data$authority_strikedown_binary[data$QI1==5]<- 0

data$authority_votedown_binary[data$QI2==1]<-1
data$authority_votedown_binary[data$QI2==2]<- 1
data$authority_votedown_binary[data$QI2==3]<- 0
data$authority_votedown_binary[data$QI2==4]<- 0
data$authority_votedown_binary[data$QI2==5]<- 0


#### Creating Variables - Mechanisms - Binary

data$mechanism_legal_binary[data$QJ1==1]<-1
data$mechanism_legal_binary[data$QJ1==2]<- 1
data$mechanism_legal_binary[data$QJ1==3]<- 0
data$mechanism_legal_binary[data$QJ1==4]<- 0
data$mechanism_legal_binary[data$QJ1==5]<- 0

data$mechanism_gradual_binary[data$QJ2==1]<-1
data$mechanism_gradual_binary[data$QJ2==2]<- 1
data$mechanism_gradual_binary[data$QJ2==3]<- 0
data$mechanism_gradual_binary[data$QJ2==4]<- 0
data$mechanism_gradual_binary[data$QJ2==5]<- 0

data$mechanism_minority_binary[data$QJ3==1]<-1
data$mechanism_minority_binary[data$QJ3==2]<- 1
data$mechanism_minority_binary[data$QJ3==3]<- 0
data$mechanism_minority_binary[data$QJ3==4]<- 0
data$mechanism_minority_binary[data$QJ3==5]<- 0

data$mechanism_illegitimate_binary[data$QJ4==1]<-1
data$mechanism_illegitimate_binary[data$QJ4==2]<- 1
data$mechanism_illegitimate_binary[data$QJ4==3]<- 0
data$mechanism_illegitimate_binary[data$QJ4==4]<- 0
data$mechanism_illegitimate_binary[data$QJ4==5]<- 0

data$mechanism_changesneeded_binary[data$QJ5==1]<-1
data$mechanism_changesneeded_binary[data$QJ5==2]<- 1
data$mechanism_changesneeded_binary[data$QJ5==3]<- 0
data$mechanism_changesneeded_binary[data$QJ5==4]<- 0
data$mechanism_changesneeded_binary[data$QJ5==5]<- 0


#### Flipping the Response Variable  - Consistency 

data$consistency[data$QK1==1]<-5
data$consistency[data$QK1==2]<- 4
data$consistency[data$QK1==3]<- 3
data$consistency[data$QK1==4]<- 2
data$consistency[data$QK1==5]<- 1

data$consistency_binary[data$QK1==1]<-1
data$consistency_binary[data$QK1==2]<- 1
data$consistency_binary[data$QK1==3]<- 0
data$consistency_binary[data$QK1==4]<- 0
data$consistency_binary[data$QK1==5]<- 0


#### Creating Treatment Variables - Substance

data$substance_treat1[data$BlockD..SubstantiveConstraints._DO=="QD|QDT1|QDD|QD1|QD2|Q107"]<-1 
data$substance_treat1[data$BlockD..SubstantiveConstraints._DO!="QD|QDT1|QDD|QD1|QD2|Q107"]<-0

data$substance_treat2[data$BlockD..SubstantiveConstraints._DO=="QD|QDT2|QDD|QD1|QD2|Q107"]<-1 
data$substance_treat2[data$BlockD..SubstantiveConstraints._DO!="QD|QDT2|QDD|QD1|QD2|Q107"]<-0

data$substance_treat3[data$BlockD..SubstantiveConstraints._DO=="QD|QDT3|QDD|QD1|QD2|Q107"]<-1 
data$substance_treat3[data$BlockD..SubstantiveConstraints._DO!="QD|QDT3|QDD|QD1|QD2|Q107"]<-0

data$substance_treat4[data$BlockD..SubstantiveConstraints._DO=="QD|QDT4|QDD|QD1|QD2|Q107"]<-1 
data$substance_treat4[data$BlockD..SubstantiveConstraints._DO!="QD|QDT4|QDD|QD1|QD2|Q107"]<-0

data$substance_treat5[data$BlockD..SubstantiveConstraints._DO=="QD|QDT5|QDD|QD1|QD2|Q107"]<-1 
data$substance_treat5[data$BlockD..SubstantiveConstraints._DO!="QD|QDT5|QDD|QD1|QD2|Q107"]<-0

data$substance_treat6[data$BlockD..SubstantiveConstraints._DO=="QD|QDT6|QDD|QD1|QD2|Q107"]<-1 
data$substance_treat6[data$BlockD..SubstantiveConstraints._DO!="QD|QDT6|QDD|QD1|QD2|Q107"]<-0

table(data$substance_treat1)
table(data$substance_treat2)
table(data$substance_treat3)
table(data$substance_treat4)
table(data$substance_treat5)
table(data$substance_treat6)

data$substance_treat_groups[data$substance_treat1==1]<-"1. Control" 
data$substance_treat_groups[data$substance_treat2==1]<-"2. Context" 
data$substance_treat_groups[data$substance_treat3==1]<-"3. Legal" 
data$substance_treat_groups[data$substance_treat4==1]<-"4. Pragmatic" 
data$substance_treat_groups[data$substance_treat5==1]<-"5. Democracy" 
data$substance_treat_groups[data$substance_treat6==1]<-"6. Combined" 

table(data$substance_treat_groups)

#### Creating Treatment Variables - Procedure

data$procedure_treat1[data$BlockE.ProceduralConstraints_DO=="QE|QET1|QEE|QE1|QE2|Q108"]<-1 
data$procedure_treat1[data$BlockE.ProceduralConstraints_DO!="QE|QET1|QEE|QE1|QE2|Q108"]<-0

data$procedure_treat2[data$BlockE.ProceduralConstraints_DO=="QE|QET2|QEE|QE1|QE2|Q108"]<-1 
data$procedure_treat2[data$BlockE.ProceduralConstraints_DO!="QE|QET2|QEE|QE1|QE2|Q108"]<-0

data$procedure_treat3[data$BlockE.ProceduralConstraints_DO=="QE|QET3|QEE|QE1|QE2|Q108"]<-1 
data$procedure_treat3[data$BlockE.ProceduralConstraints_DO!="QE|QET3|QEE|QE1|QE2|Q108"]<-0

data$procedure_treat4[data$BlockE.ProceduralConstraints_DO=="QE|QET4|QEE|QE1|QE2|Q108"]<-1 
data$procedure_treat4[data$BlockE.ProceduralConstraints_DO!="QE|QET4|QEE|QE1|QE2|Q108"]<-0

data$procedure_treat5[data$BlockE.ProceduralConstraints_DO=="QE|QET5|QEE|QE1|QE2|Q108"]<-1 
data$procedure_treat5[data$BlockE.ProceduralConstraints_DO!="QE|QET5|QEE|QE1|QE2|Q108"]<-0

data$procedure_treat6[data$BlockE.ProceduralConstraints_DO=="QE|QET6|QEE|QE1|QE2|Q108"]<-1 
data$procedure_treat6[data$BlockE.ProceduralConstraints_DO!="QE|QET6|QEE|QE1|QE2|Q108"]<-0

table(data$procedure_treat1)
table(data$procedure_treat2)
table(data$procedure_treat3)
table(data$procedure_treat4)
table(data$procedure_treat5)
table(data$procedure_treat6)

data$procedure_treat_groups[data$procedure_treat1==1]<-"1. Control" 
data$procedure_treat_groups[data$procedure_treat2==1]<-"2. Context" 
data$procedure_treat_groups[data$procedure_treat3==1]<-"3. Legal" 
data$procedure_treat_groups[data$procedure_treat4==1]<-"4. Pragmatic" 
data$procedure_treat_groups[data$procedure_treat5==1]<-"5. Democracy" 
data$procedure_treat_groups[data$procedure_treat6==1]<-"6. Combined" 

table(data$procedure_treat_groups)


#### Creating Treatment Variables - Authority

data$authority_treat1[data$BlockF.CompetencyConstraints_DO=="QF|QFT1|QFF|QF1|QF2|Q109"]<-1 
data$authority_treat1[data$BlockF.CompetencyConstraints_DO!="QF|QFT1|QFF|QF1|QF2|Q109"]<-0

data$authority_treat2[data$BlockF.CompetencyConstraints_DO=="QF|QFT2|QFF|QF1|QF2|Q109"]<-1 
data$authority_treat2[data$BlockF.CompetencyConstraints_DO!="QF|QFT2|QFF|QF1|QF2|Q109"]<-0

data$authority_treat3[data$BlockF.CompetencyConstraints_DO=="QF|QFT3|QFF|QF1|QF2|Q109"]<-1 
data$authority_treat3[data$BlockF.CompetencyConstraints_DO!="QF|QFT3|QFF|QF1|QF2|Q109"]<-0

data$authority_treat4[data$BlockF.CompetencyConstraints_DO=="QF|QFT4|QFF|QF1|QF2|Q109"]<-1 
data$authority_treat4[data$BlockF.CompetencyConstraints_DO!="QF|QFT4|QFF|QF1|QF2|Q109"]<-0

data$authority_treat5[data$BlockF.CompetencyConstraints_DO=="QF|QFT5|QFF|QF1|QF2|Q109"]<-1 
data$authority_treat5[data$BlockF.CompetencyConstraints_DO!="QF|QFT5|QFF|QF1|QF2|Q109"]<-0

data$authority_treat6[data$BlockF.CompetencyConstraints_DO=="QF|QFT6|QFF|QF1|QF2|Q109"]<-1 
data$authority_treat6[data$BlockF.CompetencyConstraints_DO!="QF|QFT6|QFF|QF1|QF2|Q109"]<-0

table(data$authority_treat1)
table(data$authority_treat2)
table(data$authority_treat3)
table(data$authority_treat4)
table(data$authority_treat5)
table(data$authority_treat6)

data$authority_treat_groups[data$authority_treat1==1]<-"1. Control" 
data$authority_treat_groups[data$authority_treat2==1]<-"2. Context" 
data$authority_treat_groups[data$authority_treat3==1]<-"3. Legal" 
data$authority_treat_groups[data$authority_treat4==1]<-"4. Pragmatic" 
data$authority_treat_groups[data$authority_treat5==1]<-"5. Democracy" 
data$authority_treat_groups[data$authority_treat6==1]<-"6. Combined" 

table(data$authority_treat_groups)


#### Creating Treatment Variables - Consistency

data$consistency_control[data$BlockK.Consistency_DO=="QK|QKT1|QKK|QK1"]<-1 
data$consistency_control[data$BlockK.Consistency_DO!="QK|QKT1|QKK|QK1"]<-0

data$consistency_treated[data$BlockK.Consistency_DO=="QK|QK2|QKK|QK1"]<-1 
data$consistency_treated[data$BlockK.Consistency_DO!="QK|QK2|QKK|QK1"]<-0

table(data$consistency_control)
table(data$consistency_treated)


######## Order of Main Questions

table(data$FL_16_DO)

data$substance_first <-0
data$substance_first[data$FL_16_DO=="BlockD-SubstantiveConstraints|BlockE-ProceduralConstraints|BlockF-CompetencyConstraints"]<-1 
data$substance_first[data$FL_16_DO=="BlockD-SubstantiveConstraints|BlockF-CompetencyConstraints|BlockE-ProceduralConstraints"]<-1 

table(data$substance_first)


data$procedure_first <-0
data$procedure_first[data$FL_16_DO=="BlockE-ProceduralConstraints|BlockD-SubstantiveConstraints|BlockF-CompetencyConstraints"]<-1 
data$procedure_first[data$FL_16_DO=="BlockE-ProceduralConstraints|BlockF-CompetencyConstraints|BlockD-SubstantiveConstraints"]<-1 

table(data$procedure_first)


data$authority_first <-0
data$authority_first[data$FL_16_DO=="BlockF-CompetencyConstraints|BlockD-SubstantiveConstraints|BlockE-ProceduralConstraints"]<-1 
data$authority_first[data$FL_16_DO=="BlockF-CompetencyConstraints|BlockE-ProceduralConstraints|BlockD-SubstantiveConstraints"]<-1 

table(data$authority_first)

1388+1344+1314



#####################################################################
######### Table 1: Summary Statistics							  ###
#####################################################################

## Gender
x <- table(data$QQ1)
y <- sum(table(data$QQ1))
z <- x/y
z <- z*100

round(z,1)


## Age
x <- table(data$QQ2)
y <- sum(table(data$QQ2))
z <- x/y
z <- z*100

round(z,1)

## Region
x <- table(data$QQ3)
y <- sum(table(data$QQ3))
z <- x/y
z <- z*100

round(z,1)

## Education
x <- table(data$QQ4)
y <- sum(table(data$QQ4))
z <- x/y
z <- z*100

round(z,1)

## Ideology 
x <- table(data$QQ5)
y <- sum(table(data$QQ5))
z <- x/y
z <- z*100

round(z,1)



###########################################################
######### Figure 1: 	Support the Process		   		   ####
###########################################################

## Support the Process 
table(data$QB3)
test1A <- (397+899)/(397+899+938+911+896)



## Plan to Vote for the Constitution
table(data$QB4)
test1B <- (1077+689)/(1077+689+609+690+975)


## Graphing

counts <- c(test1A,test1B)

par(mfrow=c(1,1),mar=c(3, 5, 1, 2),las=1)
barplot(counts,col=c("aquamarine1","aquamarine1"),names.arg=c("Drafting Process Has Been Successful","Intend to Vote for Adoption"),ylim=c(0,0.5),ylab="% of Respondents",main="",axes=F,density=c(20,40))

y.axis <- c(0,.1,.2,.3,.4,.5)
Y <- c("0","10","20","30","40","50")
axis(2,at = y.axis,labels=Y)

text(0.7,0.3207127+0.015,"32.1%")
text(1.9,0.4371287+0.015,"43.7%")



###########################################################
######### Figure 2: Polling Over Time	   		   ####
###########################################################


### Load Clean Polling Data
data_polling <- read.csv("Data_ChilePolling.csv", sep=",", header=TRUE)
dim(data_polling)
names(data_polling)
head(data_polling)

### Save Means
d1<- data_polling$approve
d2<- data_polling$unsure
d3<- data_polling$reject

counts <- rbind(d1,d2,d3)

### Graph Data 
par(mfrow=c(1,1),mar=c(3, 4, 1, 2),las=1)
barplot(counts, col=c("aquamarine1","khaki1","indianred1"),  xlab="group",xlim=c(0,120),ylab="% of Respondents")


("topright", 
       legend = c("Reject","Unsure", "Approve"), 
       fill = c("indianred1","khaki1","aquamarine1"),bty = "n")



###########################################################
######### Figure 3A: Are Constraints Binding				####
###########################################################

data$var <- data$substance_binding_binary
mean1 <- t.test(data$var,conf.level = 0.90)$estimate

data$var <- data$procedure_binding_binary
mean2 <- t.test(data$var,conf.level = 0.90)$estimate

data$var <- data$authority_binding_binary
mean3 <- t.test(data$var,conf.level = 0.90)$estimate


counts <- c(mean1,mean2,mean3)


par(mfrow=c(1,1),mar=c(3, 5, 1, 2),las=1)
barplot(counts,col=c("dodgerblue","chocolate1","mediumpurple1"),names.arg=c("Substantive","Procedural","Institutional"),ylim=c(0,1),ylab="% of Respondents",main="",axes=F,density=c(40,10,20))

y.axis <- c(0,.1,.2,.3,.4,.5,.6,.7,.8,.9,1)
Y <- c("0","10","20","30","40","50","60","70","80","90","100")
axis(2,at = y.axis,labels=Y)


x<-0.7
data$var <- data$substance_binding_binary
low <- t.test(data$var,conf.level = 0.95)[4]$conf.int[1]
upp <- t.test(data$var,conf.level = 0.95)[4]$conf.int[2]

segments( x  , low,x ,upp, col="black",lty=1,lwd=3, cex=2)
segments( x-.1  , upp,x+.1 ,upp, col="black",lty=1,lwd=3, cex=2)
segments( x-.1  , low,x+.1 ,low, col="black",lty=1,lwd=3, cex=2)
text(x,upp+0.05,"68.7%")

x<-1.9
data$var <- data$procedure_binding_binary
low <- t.test(data$var,conf.level = 0.95)[4]$conf.int[1]
upp <- t.test(data$var,conf.level = 0.95)[4]$conf.int[2]

segments( x  , low,x ,upp, col="black",lty=1,lwd=3, cex=2)
segments( x-.1  , upp,x+.1 ,upp, col="black",lty=1,lwd=3, cex=2)
segments( x-.1  , low,x+.1 ,low, col="black",lty=1,lwd=3, cex=2)
text(x,upp+0.05,"55.0%")

x<-3.1
data$var <- data$authority_binding_binary
low <- t.test(data$var,conf.level = 0.95)[4]$conf.int[1]
upp <- t.test(data$var,conf.level = 0.95)[4]$conf.int[2]

segments( x  , low,x ,upp, col="black",lty=1,lwd=3, cex=2)
segments( x-.1  , upp,x+.1 ,upp, col="black",lty=1,lwd=3, cex=2)
segments( x-.1  , low,x+.1 ,low, col="black",lty=1,lwd=3, cex=2)
text(x,upp+0.05,"60.6%")



###########################################################
######### Figure 3B: Are Constraints Good 				####
###########################################################


data$var <- data$substance_good_binary
mean1 <- t.test(data$var,conf.level = 0.90)$estimate

data$var <- data$procedure_good_binary
mean2 <- t.test(data$var,conf.level = 0.90)$estimate

data$var <- data$authority_good_binary
mean3 <- t.test(data$var,conf.level = 0.90)$estimate


counts <- c(mean1,mean2,mean3)


par(mfrow=c(1,1),mar=c(3, 5, 1, 2),las=1)
barplot(counts,col=c("dodgerblue","chocolate1","mediumpurple1"),names.arg=c("Substantive","Procedural","Institutional"),ylim=c(0,1),ylab="% of Respondents",main="",axes=F,density=c(40,10,20))

y.axis <- c(0,.1,.2,.3,.4,.5,.6,.7,.8,.9,1)
Y <- c("0","10","20","30","40","50","60","70","80","90","100")
axis(2,at = y.axis,labels=Y)


x<-0.7
data$var <- data$substance_good_binary
low <- t.test(data$var,conf.level = 0.95)[4]$conf.int[1]
upp <- t.test(data$var,conf.level = 0.95)[4]$conf.int[2]

segments( x  , low,x ,upp, col="black",lty=1,lwd=3, cex=2)
segments( x-.1  , upp,x+.1 ,upp, col="black",lty=1,lwd=3, cex=2)
segments( x-.1  , low,x+.1 ,low, col="black",lty=1,lwd=3, cex=2)
text(x,upp+0.05,"74.4%")

x<-1.9
data$var <- data$procedure_good_binary
low <- t.test(data$var,conf.level = 0.95)[4]$conf.int[1]
upp <- t.test(data$var,conf.level = 0.95)[4]$conf.int[2]

segments( x  , low,x ,upp, col="black",lty=1,lwd=3, cex=2)
segments( x-.1  , upp,x+.1 ,upp, col="black",lty=1,lwd=3, cex=2)
segments( x-.1  , low,x+.1 ,low, col="black",lty=1,lwd=3, cex=2)
text(x,upp+0.05,"41.1%")

x<-3.1
data$var <- data$authority_good_binary
low <- t.test(data$var,conf.level = 0.95)[4]$conf.int[1]
upp <- t.test(data$var,conf.level = 0.95)[4]$conf.int[2]

segments( x  , low,x ,upp, col="black",lty=1,lwd=3, cex=2)
segments( x-.1  , upp,x+.1 ,upp, col="black",lty=1,lwd=3, cex=2)
segments( x-.1  , low,x+.1 ,low, col="black",lty=1,lwd=3, cex=2)
text(x,upp+0.05,"51.7%")



############################################################################################################
####### 4A. Support for Constraining Constitutional Drafting By Treatment Group - Binding     #######
############################################################################################################


####### 1. Substance -binding

data2 <- data[data$substance_binding_binary %in% c(0,1),]

par(mar=c(4,5,4,1),mfrow=c(1,3),family="serif") 
lineplot.CI(x.factor = substance_treat_groups, response = substance_binding_binary, data =  data2,cex = 2, main="Substantive",ylab = "% of Respondents",cex.lab = 1, xlab="", x.leg = 1, col = c("dodgerblue","dodgerblue"), pch = c(16,16), ylim=c(0,1),lty=0,bty="n",yaxt="n",ci.fun=function(x) c(mean(x)-1.645*se(x), mean(x)+1.645*se(x)))
axis(side=1,at=seq(1,6,1),lwd=3,cex=2,labels=c("","","","","",""))
y.axis <- c(0,0.1,.2,.3,.4,.5,.6,.7,.8,.9,1)
Y <- c("0","10","20","30","40","50","60","70","80","90","100")
axis(2,at = y.axis,labels=Y)

segments( 0  , 0.687,7 ,0.687, col="black",lty=1,lwd=1)


####### 2. Procedural - binding 

data2 <- data[data$procedure_binding_binary %in% c(0,1),]

lineplot.CI(x.factor = procedure_treat_groups, response = procedure_binding_binary, data =  data2,cex = 2, main="Procedural",ylab = "% of Respondents",cex.lab = 1, xlab="", x.leg = 1, col = c("chocolate1","chocolate1"), pch = c(16,16), ylim=c(0,1),lty=0,bty="n",yaxt="n",ci.fun=function(x) c(mean(x)-1.645*se(x), mean(x)+1.645*se(x)))
axis(side=1,at=seq(1,6,1),lwd=3,cex=2,labels=c("","","","","",""))
y.axis <- c(0,0.1,.2,.3,.4,.5,.6,.7,.8,.9,1)
Y <- c("0","10","20","30","40","50","60","70","80","90","100")
axis(2,at = y.axis,labels=Y)

segments( 0  , 0.55,7 ,0.55, col="black",lty=1,lwd=1)



####### 3. Institutional - Binding

data2 <- data[data$authority_binding_binary %in% c(0,1),]

lineplot.CI(x.factor = authority_treat_groups, response = authority_binding_binary, data =  data2,cex = 2, main="Institutional",ylab = "% of Respondents",cex.lab = 1, xlab="", x.leg = 1, col = c("mediumpurple1","mediumpurple1"), pch = c(16,16), ylim=c(0,1),lty=0,bty="n",yaxt="n",ci.fun=function(x) c(mean(x)-1.645*se(x), mean(x)+1.645*se(x)))
axis(side=1,at=seq(1,6,1),lwd=3,cex=2,labels=c("","","","","",""))
y.axis <- c(0,0.1,.2,.3,.4,.5,.6,.7,.8,.9,1)
Y <- c("0","10","20","30","40","50","60","70","80","90","100")
axis(2,at = y.axis,labels=Y)

segments( 0  , 0.606,7 ,0.606, col="black",lty=1,lwd=1)

segments( 3  , .05,4 ,.05, col="black",lty=1,lwd=1)
text(5, 0.05, "Full Sample Mean", cex=2,col="black")

############################################################################################################
####### 4B. Support for Constraining Constitutional Drafting By Treatment Group - Good for Chile     #######
############################################################################################################


####### 1. Substance -good 

data2 <- data[data$substance_good_binary %in% c(0,1),]

par(mar=c(4,5,4,1),mfrow=c(1,3),family="serif") 
lineplot.CI(x.factor = substance_treat_groups, response = substance_good_binary, data =  data2,cex = 2, main="Substantive",ylab = "% of Respondents",cex.lab = 1, xlab="", x.leg = 1, col = c("dodgerblue","dodgerblue"), pch = c(16,16), ylim=c(0,1),lty=0,bty="n",yaxt="n",ci.fun=function(x) c(mean(x)-1.645*se(x), mean(x)+1.645*se(x)))
axis(side=1,at=seq(1,6,1),lwd=3,cex=2,labels=c("","","","","",""))
y.axis <- c(0,0.1,.2,.3,.4,.5,.6,.7,.8,.9,1)
Y <- c("0","10","20","30","40","50","60","70","80","90","100")
axis(2,at = y.axis,labels=Y)

segments( 0  , 0.744,7 ,0.744, col="black",lty=1,lwd=1)


####### 2. Procedural - Good

data2 <- data[data$procedure_good_binary %in% c(0,1),]

lineplot.CI(x.factor = procedure_treat_groups, response = procedure_good_binary, data =  data2,cex = 2, main="Procedural",ylab = "% of Respondents",cex.lab = 1, xlab="", x.leg = 1, col = c("chocolate1","chocolate1"), pch = c(16,16), ylim=c(0,1),lty=0,bty="n",yaxt="n",ci.fun=function(x) c(mean(x)-1.645*se(x), mean(x)+1.645*se(x)))
axis(side=1,at=seq(1,6,1),lwd=3,cex=2,labels=c("","","","","",""))
y.axis <- c(0,0.1,.2,.3,.4,.5,.6,.7,.8,.9,1)
Y <- c("0","10","20","30","40","50","60","70","80","90","100")
axis(2,at = y.axis,labels=Y)

segments( 0  , 0.411,7 ,0.411, col="black",lty=1,lwd=1)



####### 3. Institutional - Good

data2 <- data[data$authority_good_binary %in% c(0,1),]

lineplot.CI(x.factor = authority_treat_groups, response = authority_good_binary, data =  data2,cex = 2, main="Institutional",ylab = "% of Respondents",cex.lab = 1, xlab="", x.leg = 1, col = c("mediumpurple1","mediumpurple1"), pch = c(16,16), ylim=c(0,1),lty=0,bty="n",yaxt="n",ci.fun=function(x) c(mean(x)-1.645*se(x), mean(x)+1.645*se(x)))
axis(side=1,at=seq(1,6,1),lwd=3,cex=2,labels=c("","","","","",""))
y.axis <- c(0,0.1,.2,.3,.4,.5,.6,.7,.8,.9,1)
Y <- c("0","10","20","30","40","50","60","70","80","90","100")
axis(2,at = y.axis,labels=Y)

segments( 0  , 0.517,7 ,0.517, col="black",lty=1,lwd=1)

segments( 3  , .05,4 ,.05, col="black",lty=1,lwd=1)
text(5, 0.05, "Full Sample Mean", cex=2,col="black")

#####################################################################
######### Figure 5A: Are Violations Enough to Strike Down			 ####
#####################################################################


data$var <- data$substance_strikedown_binary
mean1 <- t.test(data$var,conf.level = 0.90)$estimate

data$var <- data$procedure_strikedown_binary
mean2 <- t.test(data$var,conf.level = 0.90)$estimate

data$var <- data$authority_strikedown_binary
mean3 <- t.test(data$var,conf.level = 0.90)$estimate


counts <- c(mean1,mean2,mean3)


par(mfrow=c(1,1),mar=c(3, 5, 1, 2),las=1)
barplot(counts,col=c("dodgerblue","chocolate1","mediumpurple1"),names.arg=c("Substantive","Procedural","Institutional"),ylim=c(0,1),ylab="% of Respondents",main="",axes=F,density=c(40,10,20))

y.axis <- c(0,.1,.2,.3,.4,.5,.6,.7,.8,.9,1)
Y <- c("0","10","20","30","40","50","60","70","80","90","100")
axis(2,at = y.axis,labels=Y)


x<-0.7
data$var <- data$substance_strikedown_binary
low <- t.test(data$var,conf.level = 0.95)[4]$conf.int[1]
upp <- t.test(data$var,conf.level = 0.95)[4]$conf.int[2]

segments( x  , low,x ,upp, col="black",lty=1,lwd=3, cex=2)
segments( x-.1  , upp,x+.1 ,upp, col="black",lty=1,lwd=3, cex=2)
segments( x-.1  , low,x+.1 ,low, col="black",lty=1,lwd=3, cex=2)
text(x,upp+0.05,"64.8%")

x<-1.9
data$var <- data$procedure_strikedown_binary
low <- t.test(data$var,conf.level = 0.95)[4]$conf.int[1]
upp <- t.test(data$var,conf.level = 0.95)[4]$conf.int[2]

segments( x  , low,x ,upp, col="black",lty=1,lwd=3, cex=2)
segments( x-.1  , upp,x+.1 ,upp, col="black",lty=1,lwd=3, cex=2)
segments( x-.1  , low,x+.1 ,low, col="black",lty=1,lwd=3, cex=2)
text(x,upp+0.05,"56.0%")

x<-3.1
data$var <- data$authority_strikedown_binary
low <- t.test(data$var,conf.level = 0.95)[4]$conf.int[1]
upp <- t.test(data$var,conf.level = 0.95)[4]$conf.int[2]

segments( x  , low,x ,upp, col="black",lty=1,lwd=3, cex=2)
segments( x-.1  , upp,x+.1 ,upp, col="black",lty=1,lwd=3, cex=2)
segments( x-.1  , low,x+.1 ,low, col="black",lty=1,lwd=3, cex=2)
text(x,upp+0.05,"55.8%")




#####################################################################
######### Figure 5B: Are Violations Enough to Vote Down			 ####
#####################################################################


data$var <- data$substance_votedown_binary
mean1 <- t.test(data$var,conf.level = 0.90)$estimate

data$var <- data$procedure_votedown_binary
mean2 <- t.test(data$var,conf.level = 0.90)$estimate

data$var <- data$authority_votedown_binary
mean3 <- t.test(data$var,conf.level = 0.90)$estimate


counts <- c(mean1,mean2,mean3)


par(mfrow=c(1,1),mar=c(3, 5, 1, 2),las=1)
barplot(counts,col=c("dodgerblue","chocolate1","mediumpurple1"),names.arg=c("Substantive","Procedural","Institutional"),ylim=c(0,1),ylab="% of Respondents",main="",axes=F,density=c(40,10,20))

y.axis <- c(0,.1,.2,.3,.4,.5,.6,.7,.8,.9,1)
Y <- c("0","10","20","30","40","50","60","70","80","90","100")
axis(2,at = y.axis,labels=Y)


x<-0.7
data$var <- data$substance_votedown_binary
low <- t.test(data$var,conf.level = 0.95)[4]$conf.int[1]
upp <- t.test(data$var,conf.level = 0.95)[4]$conf.int[2]

segments( x  , low,x ,upp, col="black",lty=1,lwd=3, cex=2)
segments( x-.1  , upp,x+.1 ,upp, col="black",lty=1,lwd=3, cex=2)
segments( x-.1  , low,x+.1 ,low, col="black",lty=1,lwd=3, cex=2)
text(x,upp+0.05,"62.0%")

x<-1.9
data$var <- data$procedure_votedown_binary
low <- t.test(data$var,conf.level = 0.95)[4]$conf.int[1]
upp <- t.test(data$var,conf.level = 0.95)[4]$conf.int[2]

segments( x  , low,x ,upp, col="black",lty=1,lwd=3, cex=2)
segments( x-.1  , upp,x+.1 ,upp, col="black",lty=1,lwd=3, cex=2)
segments( x-.1  , low,x+.1 ,low, col="black",lty=1,lwd=3, cex=2)
text(x,upp+0.05,"54.6%")

x<-3.1
data$var <- data$authority_votedown_binary
low <- t.test(data$var,conf.level = 0.95)[4]$conf.int[1]
upp <- t.test(data$var,conf.level = 0.95)[4]$conf.int[2]

segments( x  , low,x ,upp, col="black",lty=1,lwd=3, cex=2)
segments( x-.1  , upp,x+.1 ,upp, col="black",lty=1,lwd=3, cex=2)
segments( x-.1  , low,x+.1 ,low, col="black",lty=1,lwd=3, cex=2)
text(x,upp+0.05,"54.6%")


#####################################################################
######### Figure 6: Mechanisms			 ####
#####################################################################

summary(data$mechanism_legal_binary)
summary(data$mechanism_gradual_binary)
summary(data$mechanism_minority_binary)
summary(data$mechanism_illegitimate_binary)
summary(data$mechanism_changesneeded_binary)



data$var <- data$mechanism_legal_binary
mean1 <- t.test(data$var,conf.level = 0.90)$estimate

data$var <- data$mechanism_gradual_binary
mean2 <- t.test(data$var,conf.level = 0.90)$estimate

data$var <- data$mechanism_minority_binary
mean3 <- t.test(data$var,conf.level = 0.90)$estimate

data$var <- data$mechanism_illegitimate_binary
mean4 <- t.test(data$var,conf.level = 0.90)$estimate

data$var <- data$mechanism_changesneeded_binary
mean5 <- t.test(data$var,conf.level = 0.90)$estimate


counts <- c(mean1,mean2,mean3,mean4,mean5)


par(mfrow=c(1,1),mar=c(3, 5, 1, 2),las=1)
barplot(counts,col=c("dodgerblue","dodgerblue","dodgerblue","dodgerblue","dodgerblue"),names.arg=c("Always Following Legal \n Rules is Important ","Change to Political Institutions \n Should Occur Gradually","Minority Political Groups \n Should be Protected","Chile's Current \n Constitution is Illegitimate","Chile Needs Major \n Changes to Government"),ylim=c(0,1),ylab="% of Respondents",main="",axes=F,density=c(40,10,20))

y.axis <- c(0,.1,.2,.3,.4,.5,.6,.7,.8,.9,1)
Y <- c("0","10","20","30","40","50","60","70","80","90","100")
axis(2,at = y.axis,labels=Y)


x<-0.7
data$var <- data$mechanism_legal_binary
low <- t.test(data$var,conf.level = 0.95)[4]$conf.int[1]
upp <- t.test(data$var,conf.level = 0.95)[4]$conf.int[2]

segments( x  , low,x ,upp, col="black",lty=1,lwd=3, cex=2)
segments( x-.1  , upp,x+.1 ,upp, col="black",lty=1,lwd=3, cex=2)
segments( x-.1  , low,x+.1 ,low, col="black",lty=1,lwd=3, cex=2)
text(x,upp+0.05,"83.9%")

x<-1.9
data$var <- data$mechanism_gradual_binary
low <- t.test(data$var,conf.level = 0.95)[4]$conf.int[1]
upp <- t.test(data$var,conf.level = 0.95)[4]$conf.int[2]

segments( x  , low,x ,upp, col="black",lty=1,lwd=3, cex=2)
segments( x-.1  , upp,x+.1 ,upp, col="black",lty=1,lwd=3, cex=2)
segments( x-.1  , low,x+.1 ,low, col="black",lty=1,lwd=3, cex=2)
text(x,upp+0.05,"59.4%")

x<-3.1
data$var <- data$mechanism_minority_binary
low <- t.test(data$var,conf.level = 0.95)[4]$conf.int[1]
upp <- t.test(data$var,conf.level = 0.95)[4]$conf.int[2]

segments( x  , low,x ,upp, col="black",lty=1,lwd=3, cex=2)
segments( x-.1  , upp,x+.1 ,upp, col="black",lty=1,lwd=3, cex=2)
segments( x-.1  , low,x+.1 ,low, col="black",lty=1,lwd=3, cex=2)
text(x,upp+0.05,"67.3%")


x<-4.3
data$var <- data$mechanism_illegitimate_binary
low <- t.test(data$var,conf.level = 0.95)[4]$conf.int[1]
upp <- t.test(data$var,conf.level = 0.95)[4]$conf.int[2]

segments( x  , low,x ,upp, col="black",lty=1,lwd=3, cex=2)
segments( x-.1  , upp,x+.1 ,upp, col="black",lty=1,lwd=3, cex=2)
segments( x-.1  , low,x+.1 ,low, col="black",lty=1,lwd=3, cex=2)
text(x,upp+0.05,"35.8%")

x<-5.5
data$var <- data$mechanism_changesneeded_binary
low <- t.test(data$var,conf.level = 0.95)[4]$conf.int[1]
upp <- t.test(data$var,conf.level = 0.95)[4]$conf.int[2]

segments( x  , low,x ,upp, col="black",lty=1,lwd=3, cex=2)
segments( x-.1  , upp,x+.1 ,upp, col="black",lty=1,lwd=3, cex=2)
segments( x-.1  , low,x+.1 ,low, col="black",lty=1,lwd=3, cex=2)
text(x,upp+0.05,"82.1%")

#####################################################################
######### Figure 7: Support for Nationalizing Mines				  ###
#####################################################################

data2 <- data[data$consistency_control %in% c(1),]
data2$var <- data2$consistency_binary
mean1 <- t.test(data2$var,conf.level = 0.90)$estimate

data3 <- data[data$consistency_treated %in% c(1),]
data3$var <- data3$consistency_binary
mean2 <- t.test(data3$var,conf.level = 0.90)$estimate

t.test(data3$var,data2$var,conf.level = 0.90)

counts <- c(mean1,mean2)

par(mfrow=c(1,1),mar=c(3, 5, 1, 2),las=1)
barplot(counts,col=c("aquamarine1","indianred1"),names.arg=c("Control","Treated"),ylim=c(0,1),ylab="% of Respondents",main="",axes=F,density=c(20,40))

y.axis <- c(0,.1,.2,.3,.4,.5,.6,.7,.8,.9,1)
Y <- c("0","10","20","30","40","50","60","70","80","90","100")
axis(2,at = y.axis,labels=Y)

x<-0.7
data2$var <- data2$consistency_binary
low <- t.test(data2$var,conf.level = 0.95)[4]$conf.int[1]
upp <- t.test(data2$var,conf.level = 0.95)[4]$conf.int[2]

segments( x  , low,x ,upp, col="black",lty=1,lwd=3, cex=2)
segments( x-.1  , upp,x+.1 ,upp, col="black",lty=1,lwd=3, cex=2)
segments( x-.1  , low,x+.1 ,low, col="black",lty=1,lwd=3, cex=2)
text(x,upp+0.05,"56.6%")

x<-1.9
data3$var <- data3$consistency_binary
low <- t.test(data3$var,conf.level = 0.95)[4]$conf.int[1]
upp <- t.test(data3$var,conf.level = 0.95)[4]$conf.int[2]

segments( x  , low,x ,upp, col="black",lty=1,lwd=3, cex=2)
segments( x-.1  , upp,x+.1 ,upp, col="black",lty=1,lwd=3, cex=2)
segments( x-.1  , low,x+.1 ,low, col="black",lty=1,lwd=3, cex=2)
text(x,upp+0.05,"54.6%")


#####################################################################
######### Figure 8A: Consistency by Views on Constraints			 ####
#####################################################################


data2 <- data[data$consistency_control %in% c(1),]
data3 <- data[data$consistency_treated %in% c(1),]

counts <- c(0,0,0,0)


par(mfrow=c(1,1),mar=c(4, 5, 3, 2),las=1)
barplot(counts,col=c("white"),names.arg=c("Substantive Constraints \n Are Binding","Substantive Constraints \n Are Good for Chile","Courts Should \n Strike Down","Citizens Should \n Vote Down"),ylim=c(-9,35),ylab="Percentage Point Change",main="",axes=F)

y.axis <- c(-5,0,5,10,15,20,25,30,35)
Y <- c("-5","0","5","10","15","20","25","30","35")
axis(2,at = y.axis,labels=Y)


abline(h=0, col="black")
abline(h=-5, col="gray",lty=3)
abline(h=5, col="gray",lty=3)
abline(h=10, col="gray",lty=3)
abline(h=15, col="gray",lty=3)
abline(h=20, col="gray",lty=3)
abline(h=25, col="gray",lty=3)
abline(h=30, col="gray",lty=3)
abline(h=35, col="gray",lty=3)

# segments(4.0 , 25, 5,25, col="white",lty=1,lwd=10)


#### Creating a Legend
# points(x=   4.2    , y=28, pch=15,col=c1,lwd=2)
# segments(4.1 , 28, 4.3,28, col=c1,lty=1,lwd=2)
# text(4.43,28,"Control",cex=0.5)

# points(x=   4.2    , y=26, pch=15,col=c1,lwd=2)
# segments(4.1 , 26, 4.3,26, col=c1,lty=3,lwd=2)
# text(4.62,26,"Control + Demographics",cex=0.5)

# points(x=   4.2    , y=24, pch=19,col=c2,lwd=2)
# segments(4.1 , 24, 4.3,24, col=c2,lty=1,lwd=2)
# text(4.46,24,"Treatment",cex=0.5)

# points(x=   4.2    , y=22, pch=19,col=c2,lwd=2)
# segments(4.1 , 22, 4.3,22, col=c2,lty=3,lwd=2)
# text(4.65,22,"Treatment + Demographics",cex=0.5)

#### Setting the Colors

c1 <-"aquamarine1"
c2 <-"indianred1"

########## Constraints Are Binding #################

b <- 0.5

## Control + No Demographics 
a <- 0.0
n <- b+a

regX <- lm(data2$consistency_binary ~ data2$substance_binding_binary) 
coef <- summary(regX)$coefficients[2]
se <- summary(regX)$coefficients[4]
smd_l <- coef-(1.645*se)
smd_u <- coef+(1.645*se)
coef<- coef*100
smd_l<- smd_l*100
smd_u<- smd_u*100

points(x=   n    , y=coef, pch=15,col=c1,lwd=7,cex=2)
segments(n , smd_l, n,smd_u, col=c1,lty=1,lwd=5)

## Control + Demographics 
a <- 0.1
n <- b+a

regX <- lm(data2$consistency_binary ~ data2$substance_binding_binary++as.factor(data2$QQ1)+as.factor(data2$QQ2)+as.factor(data2$QQ3)+as.factor(data2$QQ4)+as.factor(data2$QQ5)) 
coef <- summary(regX)$coefficients[2]
se <- summary(regX)$coefficients[2,2]
smd_l <- coef-(1.645*se)
smd_u <- coef+(1.645*se)
coef<- coef*100
smd_l<- smd_l*100
smd_u<- smd_u*100

points(x=   n    , y=coef, pch=15,col=c1,lwd=7,cex=2)
segments(n , smd_l, n,smd_u, col=c1,lty=3,lwd=5)


## Treatment + No Demographics 
a <- 0.3
n <- b+a

regX <- lm(data3$consistency_binary ~ data3$substance_binding_binary) 
coef <- summary(regX)$coefficients[2]
se <- summary(regX)$coefficients[4]
smd_l <- coef-(1.645*se)
smd_u <- coef+(1.645*se)
coef<- coef*100
smd_l<- smd_l*100
smd_u<- smd_u*100

points(x=   n    , y=coef, pch=19,col=c2,lwd=7)
segments(n , smd_l, n,smd_u, col=c2,lty=1,lwd=5)

## Treatment + Demographics 
a <- 0.4
n <- b+a

regX <- lm(data3$consistency_binary ~ data3$substance_binding_binary++as.factor(data3$QQ1)+as.factor(data3$QQ2)+as.factor(data3$QQ3)+as.factor(data3$QQ4)+as.factor(data3$QQ5)) 
coef <- summary(regX)$coefficients[2]
se <- summary(regX)$coefficients[2,2]
smd_l <- coef-(1.645*se)
smd_u <- coef+(1.645*se)
coef<- coef*100
smd_l<- smd_l*100
smd_u<- smd_u*100

points(x=   n    , y=coef, pch=19,col=c2,lwd=7)
segments(n , smd_l, n,smd_u, col=c2,lty=3,lwd=5)


########## Constraints Are Good #################

b <- 1.7

## Control + No Demographics 
a <- 0.0
n <- b+a

regX <- lm(data2$consistency_binary ~ data2$substance_good_binary) 
coef <- summary(regX)$coefficients[2]
se <- summary(regX)$coefficients[4]
smd_l <- coef-(1.645*se)
smd_u <- coef+(1.645*se)
coef<- coef*100
smd_l<- smd_l*100
smd_u<- smd_u*100

points(x=   n    , y=coef, pch=15,col=c1,lwd=7,cex=2)
segments(n , smd_l, n,smd_u, col=c1,lty=1,lwd=5)

## Control + Demographics 
a <- 0.1
n <- b+a

regX <- lm(data2$consistency_binary ~ data2$substance_good_binary++as.factor(data2$QQ1)+as.factor(data2$QQ2)+as.factor(data2$QQ3)+as.factor(data2$QQ4)+as.factor(data2$QQ5)) 
coef <- summary(regX)$coefficients[2]
se <- summary(regX)$coefficients[2,2]
smd_l <- coef-(1.645*se)
smd_u <- coef+(1.645*se)
coef<- coef*100
smd_l<- smd_l*100
smd_u<- smd_u*100

points(x=   n    , y=coef, pch=15,col=c1,lwd=7,cex=2)
segments(n , smd_l, n,smd_u, col=c1,lty=3,lwd=5)


## Treatment + No Demographics 
a <- 0.3
n <- b+a

regX <- lm(data3$consistency_binary ~ data3$substance_good_binary) 
coef <- summary(regX)$coefficients[2]
se <- summary(regX)$coefficients[4]
smd_l <- coef-(1.645*se)
smd_u <- coef+(1.645*se)
coef<- coef*100
smd_l<- smd_l*100
smd_u<- smd_u*100

points(x=   n    , y=coef, pch=19,col=c2,lwd=7)
segments(n , smd_l, n,smd_u, col=c2,lty=1,lwd=5)

## Treatment + Demographics 
a <- 0.4
n <- b+a

regX <- lm(data3$consistency_binary ~ data3$substance_good_binary++as.factor(data3$QQ1)+as.factor(data3$QQ2)+as.factor(data3$QQ3)+as.factor(data3$QQ4)+as.factor(data3$QQ5)) 
coef <- summary(regX)$coefficients[2]
se <- summary(regX)$coefficients[2,2]
smd_l <- coef-(1.645*se)
smd_u <- coef+(1.645*se)
coef<- coef*100
smd_l<- smd_l*100
smd_u<- smd_u*100

points(x=   n    , y=coef, pch=19,col=c2,lwd=7)
segments(n , smd_l, n,smd_u, col=c2,lty=3,lwd=5)




########## Courts Should Strike Down #################

b <- 2.9

## Control + No Demographics 
a <- 0.0
n <- b+a

regX <- lm(data2$consistency_binary ~ data2$substance_strikedown_binary) 
coef <- summary(regX)$coefficients[2]
se <- summary(regX)$coefficients[4]
smd_l <- coef-(1.645*se)
smd_u <- coef+(1.645*se)
coef<- coef*100
smd_l<- smd_l*100
smd_u<- smd_u*100

points(x=   n    , y=coef, pch=15,col=c1,lwd=7,cex=2)
segments(n , smd_l, n,smd_u, col=c1,lty=1,lwd=5)

## Control + Demographics 
a <- 0.1
n <- b+a

regX <- lm(data2$consistency_binary ~ data2$substance_strikedown_binary++as.factor(data2$QQ1)+as.factor(data2$QQ2)+as.factor(data2$QQ3)+as.factor(data2$QQ4)+as.factor(data2$QQ5)) 
coef <- summary(regX)$coefficients[2]
se <- summary(regX)$coefficients[2,2]
smd_l <- coef-(1.645*se)
smd_u <- coef+(1.645*se)
coef<- coef*100
smd_l<- smd_l*100
smd_u<- smd_u*100

points(x=   n    , y=coef, pch=15,col=c1,lwd=7,cex=2)
segments(n , smd_l, n,smd_u, col=c1,lty=3,lwd=5)


## Treatment + No Demographics 
a <- 0.3
n <- b+a

regX <- lm(data3$consistency_binary ~ data3$substance_strikedown_binary) 
coef <- summary(regX)$coefficients[2]
se <- summary(regX)$coefficients[4]
smd_l <- coef-(1.645*se)
smd_u <- coef+(1.645*se)
coef<- coef*100
smd_l<- smd_l*100
smd_u<- smd_u*100

points(x=   n    , y=coef, pch=19,col=c2,lwd=7)
segments(n , smd_l, n,smd_u, col=c2,lty=1,lwd=5)

## Treatment + Demographics 
a <- 0.4
n <- b+a

regX <- lm(data3$consistency_binary ~ data3$substance_strikedown_binary++as.factor(data3$QQ1)+as.factor(data3$QQ2)+as.factor(data3$QQ3)+as.factor(data3$QQ4)+as.factor(data3$QQ5)) 
coef <- summary(regX)$coefficients[2]
se <- summary(regX)$coefficients[2,2]
smd_l <- coef-(1.645*se)
smd_u <- coef+(1.645*se)
coef<- coef*100
smd_l<- smd_l*100
smd_u<- smd_u*100

points(x=   n    , y=coef, pch=19,col=c2,lwd=7)
segments(n , smd_l, n,smd_u, col=c2,lty=3,lwd=5)



########## Citizens Should Vote Down #################

b <- 4.2

## Control + No Demographics 
a <- 0.0
n <- b+a

regX <- lm(data2$consistency_binary ~ data2$substance_votedown_binary) 
coef <- summary(regX)$coefficients[2]
se <- summary(regX)$coefficients[4]
smd_l <- coef-(1.645*se)
smd_u <- coef+(1.645*se)
coef<- coef*100
smd_l<- smd_l*100
smd_u<- smd_u*100

points(x=   n    , y=coef, pch=15,col=c1,lwd=7,cex=2)
segments(n , smd_l, n,smd_u, col=c1,lty=1,lwd=5)

## Control + Demographics 
a <- 0.1
n <- b+a

regX <- lm(data2$consistency_binary ~ data2$substance_votedown_binary++as.factor(data2$QQ1)+as.factor(data2$QQ2)+as.factor(data2$QQ3)+as.factor(data2$QQ4)+as.factor(data2$QQ5)) 
coef <- summary(regX)$coefficients[2]
se <- summary(regX)$coefficients[2,2]
smd_l <- coef-(1.645*se)
smd_u <- coef+(1.645*se)
coef<- coef*100
smd_l<- smd_l*100
smd_u<- smd_u*100

points(x=   n    , y=coef, pch=15,col=c1,lwd=7,cex=2)
segments(n , smd_l, n,smd_u, col=c1,lty=3,lwd=5)


## Treatment + No Demographics 
a <- 0.3
n <- b+a

regX <- lm(data3$consistency_binary ~ data3$substance_votedown_binary) 
coef <- summary(regX)$coefficients[2]
se <- summary(regX)$coefficients[4]
smd_l <- coef-(1.645*se)
smd_u <- coef+(1.645*se)
coef<- coef*100
smd_l<- smd_l*100
smd_u<- smd_u*100

points(x=   n    , y=coef, pch=19,col=c2,lwd=7)
segments(n , smd_l, n,smd_u, col=c2,lty=1,lwd=5)

## Treatment + Demographics 
a <- 0.4
n <- b+a

regX <- lm(data3$consistency_binary ~ data3$substance_votedown_binary++as.factor(data3$QQ1)+as.factor(data3$QQ2)+as.factor(data3$QQ3)+as.factor(data3$QQ4)+as.factor(data3$QQ5)) 
coef <- summary(regX)$coefficients[2]
se <- summary(regX)$coefficients[2,2]
smd_l <- coef-(1.645*se)
smd_u <- coef+(1.645*se)
coef<- coef*100
smd_l<- smd_l*100
smd_u<- smd_u*100

points(x=   n    , y=coef, pch=19,col=c2,lwd=7)
segments(n , smd_l, n,smd_u, col=c2,lty=3,lwd=5)




#####################################################################
######### Figure 8B: Consistency by Mechanism	 ####
#####################################################################

data2 <- data[data$consistency_control %in% c(1),]
data3 <- data[data$consistency_treated %in% c(1),]

counts <- c(0,0,0,0,0)


par(mfrow=c(1,1),mar=c(4, 5, 3, 2),las=1)
barplot(counts,col=c("white"),names.arg=c("Always Following Legal \n Rules is Important","Change to Political Institutions \n Should Occur Gradually","Minority Political Groups \n Should be Protected","Chile's Current \n Constitution is Illegitimate","Chile Needs Major \n Changes to Government"),ylim=c(-9,35),ylab="Percentage Point Change",main="",axes=F)



y.axis <- c(-5,0,5,10,15,20,25,30,35)
Y <- c("-5","0","5","10","15","20","25","30","35")
axis(2,at = y.axis,labels=Y)


abline(h=0, col="black")
abline(h=-5, col="gray",lty=3)
abline(h=5, col="gray",lty=3)
abline(h=10, col="gray",lty=3)
abline(h=15, col="gray",lty=3)
abline(h=20, col="gray",lty=3)
abline(h=25, col="gray",lty=3)
abline(h=30, col="gray",lty=3)
abline(h=35, col="gray",lty=3)

# segments(5.0 , 5, 6.5,5, col="white",lty=1,lwd=10)


#### Creating a Legend
# points(x=   5.2    , y=8, pch=15,col=c1,lwd=2)
# segments(5.1 , 8, 5.3,8, col=c1,lty=1,lwd=2)
# text(5.43,8,"Control",cex=0.5)

# points(x=   5.2    , y=6, pch=15,col=c1,lwd=2)
# segments(5.1 , 6, 5.3,6, col=c1,lty=3,lwd=2)
# text(5.62,6,"Control + Demographics",cex=0.5)

# points(x=   5.2    , y=4, pch=19,col=c2,lwd=2)
# segments(5.1 , 4, 5.3,4, col=c2,lty=1,lwd=2)
# text(5.46,4,"Treatment",cex=0.5)

# points(x=   5.2    , y=2, pch=19,col=c2,lwd=2)
# segments(5.1 , 2, 5.3,2, col=c2,lty=3,lwd=2)
# text(5.65,2,"Treatment + Demographics",cex=0.5)

#### Setting the Colors

c1 <-"aquamarine1"
c2 <-"indianred1"

summary(data$mechanism_legal_binary)
summary(data$mechanism_gradual_binary)
summary(data$mechanism_minority_binary)
summary(data$mechanism_illegitimate_binary)
summary(data$mechanism_changesneeded_binary)

########## Legal Rules #################

b <- 0.5

## Control + No Demographics 
a <- 0.0
n <- b+a

regX <- lm(data2$consistency_binary ~ data2$mechanism_legal_binary) 
coef <- summary(regX)$coefficients[2]
se <- summary(regX)$coefficients[4]
smd_l <- coef-(1.645*se)
smd_u <- coef+(1.645*se)
coef<- coef*100
smd_l<- smd_l*100
smd_u<- smd_u*100

points(x=   n    , y=coef, pch=15,col=c1,lwd=7,cex=2)
segments(n , smd_l, n,smd_u, col=c1,lty=1,lwd=5)

## Control + Demographics 
a <- 0.1
n <- b+a

regX <- lm(data2$consistency_binary ~ data2$mechanism_legal_binary++as.factor(data2$QQ1)+as.factor(data2$QQ2)+as.factor(data2$QQ3)+as.factor(data2$QQ4)+as.factor(data2$QQ5)) 
coef <- summary(regX)$coefficients[2]
se <- summary(regX)$coefficients[2,2]
smd_l <- coef-(1.645*se)
smd_u <- coef+(1.645*se)
coef<- coef*100
smd_l<- smd_l*100
smd_u<- smd_u*100

points(x=   n    , y=coef, pch=15,col=c1,lwd=7,cex=2)
segments(n , smd_l, n,smd_u, col=c1,lty=3,lwd=5)


## Treatment + No Demographics 
a <- 0.3
n <- b+a

regX <- lm(data3$consistency_binary ~ data3$mechanism_legal_binary) 
coef <- summary(regX)$coefficients[2]
se <- summary(regX)$coefficients[4]
smd_l <- coef-(1.645*se)
smd_u <- coef+(1.645*se)
coef<- coef*100
smd_l<- smd_l*100
smd_u<- smd_u*100

points(x=   n    , y=coef, pch=19,col=c2,lwd=7)
segments(n , smd_l, n,smd_u, col=c2,lty=1,lwd=5)

## Treatment + Demographics 
a <- 0.4
n <- b+a

regX <- lm(data3$consistency_binary ~ data3$mechanism_legal_binary++as.factor(data3$QQ1)+as.factor(data3$QQ2)+as.factor(data3$QQ3)+as.factor(data3$QQ4)+as.factor(data3$QQ5)) 
coef <- summary(regX)$coefficients[2]
se <- summary(regX)$coefficients[2,2]
smd_l <- coef-(1.645*se)
smd_u <- coef+(1.645*se)
coef<- coef*100
smd_l<- smd_l*100
smd_u<- smd_u*100

points(x=   n    , y=coef, pch=19,col=c2,lwd=7)
segments(n , smd_l, n,smd_u, col=c2,lty=3,lwd=5)


########## Gradual Change #################

b <- 1.7

## Control + No Demographics 
a <- 0.0
n <- b+a

regX <- lm(data2$consistency_binary ~ data2$mechanism_gradual_binary) 
coef <- summary(regX)$coefficients[2]
se <- summary(regX)$coefficients[4]
smd_l <- coef-(1.645*se)
smd_u <- coef+(1.645*se)
coef<- coef*100
smd_l<- smd_l*100
smd_u<- smd_u*100

points(x=   n    , y=coef, pch=15,col=c1,lwd=7,cex=2)
segments(n , smd_l, n,smd_u, col=c1,lty=1,lwd=5)

## Control + Demographics 
a <- 0.1
n <- b+a

regX <- lm(data2$consistency_binary ~ data2$mechanism_gradual_binary++as.factor(data2$QQ1)+as.factor(data2$QQ2)+as.factor(data2$QQ3)+as.factor(data2$QQ4)+as.factor(data2$QQ5)) 
coef <- summary(regX)$coefficients[2]
se <- summary(regX)$coefficients[2,2]
smd_l <- coef-(1.645*se)
smd_u <- coef+(1.645*se)
coef<- coef*100
smd_l<- smd_l*100
smd_u<- smd_u*100

points(x=   n    , y=coef, pch=15,col=c1,lwd=7,cex=2)
segments(n , smd_l, n,smd_u, col=c1,lty=3,lwd=5)


## Treatment + No Demographics 
a <- 0.3
n <- b+a

regX <- lm(data3$consistency_binary ~ data3$mechanism_gradual_binary) 
coef <- summary(regX)$coefficients[2]
se <- summary(regX)$coefficients[4]
smd_l <- coef-(1.645*se)
smd_u <- coef+(1.645*se)
coef<- coef*100
smd_l<- smd_l*100
smd_u<- smd_u*100

points(x=   n    , y=coef, pch=19,col=c2,lwd=7)
segments(n , smd_l, n,smd_u, col=c2,lty=1,lwd=5)

## Treatment + Demographics 
a <- 0.4
n <- b+a

regX <- lm(data3$consistency_binary ~ data3$mechanism_gradual_binary++as.factor(data3$QQ1)+as.factor(data3$QQ2)+as.factor(data3$QQ3)+as.factor(data3$QQ4)+as.factor(data3$QQ5)) 
coef <- summary(regX)$coefficients[2]
se <- summary(regX)$coefficients[2,2]
smd_l <- coef-(1.645*se)
smd_u <- coef+(1.645*se)
coef<- coef*100
smd_l<- smd_l*100
smd_u<- smd_u*100

points(x=   n    , y=coef, pch=19,col=c2,lwd=7)
segments(n , smd_l, n,smd_u, col=c2,lty=3,lwd=5)




########## Protect Minorities #################

b <- 2.9

## Control + No Demographics 
a <- 0.0
n <- b+a

regX <- lm(data2$consistency_binary ~ data2$mechanism_minority_binary) 
coef <- summary(regX)$coefficients[2]
se <- summary(regX)$coefficients[4]
smd_l <- coef-(1.645*se)
smd_u <- coef+(1.645*se)
coef<- coef*100
smd_l<- smd_l*100
smd_u<- smd_u*100

points(x=   n    , y=coef, pch=15,col=c1,lwd=7,cex=2)
segments(n , smd_l, n,smd_u, col=c1,lty=1,lwd=5)

## Control + Demographics 
a <- 0.1
n <- b+a

regX <- lm(data2$consistency_binary ~ data2$mechanism_minority_binary++as.factor(data2$QQ1)+as.factor(data2$QQ2)+as.factor(data2$QQ3)+as.factor(data2$QQ4)+as.factor(data2$QQ5)) 
coef <- summary(regX)$coefficients[2]
se <- summary(regX)$coefficients[2,2]
smd_l <- coef-(1.645*se)
smd_u <- coef+(1.645*se)
coef<- coef*100
smd_l<- smd_l*100
smd_u<- smd_u*100

points(x=   n    , y=coef, pch=15,col=c1,lwd=7,cex=2)
segments(n , smd_l, n,smd_u, col=c1,lty=3,lwd=5)


## Treatment + No Demographics 
a <- 0.3
n <- b+a

regX <- lm(data3$consistency_binary ~ data3$mechanism_minority_binary) 
coef <- summary(regX)$coefficients[2]
se <- summary(regX)$coefficients[4]
smd_l <- coef-(1.645*se)
smd_u <- coef+(1.645*se)
coef<- coef*100
smd_l<- smd_l*100
smd_u<- smd_u*100

points(x=   n    , y=coef, pch=19,col=c2,lwd=7)
segments(n , smd_l, n,smd_u, col=c2,lty=1,lwd=5)

## Treatment + Demographics 
a <- 0.4
n <- b+a

regX <- lm(data3$consistency_binary ~ data3$mechanism_minority_binary++as.factor(data3$QQ1)+as.factor(data3$QQ2)+as.factor(data3$QQ3)+as.factor(data3$QQ4)+as.factor(data3$QQ5)) 
coef <- summary(regX)$coefficients[2]
se <- summary(regX)$coefficients[2,2]
smd_l <- coef-(1.645*se)
smd_u <- coef+(1.645*se)
coef<- coef*100
smd_l<- smd_l*100
smd_u<- smd_u*100

points(x=   n    , y=coef, pch=19,col=c2,lwd=7)
segments(n , smd_l, n,smd_u, col=c2,lty=3,lwd=5)



########## Constitution Illegitimate #################

b <- 4.2

## Control + No Demographics 
a <- 0.0
n <- b+a

regX <- lm(data2$consistency_binary ~ data2$mechanism_illegitimate_binary) 
coef <- summary(regX)$coefficients[2]
se <- summary(regX)$coefficients[4]
smd_l <- coef-(1.645*se)
smd_u <- coef+(1.645*se)
coef<- coef*100
smd_l<- smd_l*100
smd_u<- smd_u*100

points(x=   n    , y=coef, pch=15,col=c1,lwd=7,cex=2)
segments(n , smd_l, n,smd_u, col=c1,lty=1,lwd=5)

## Control + Demographics 
a <- 0.1
n <- b+a

regX <- lm(data2$consistency_binary ~ data2$mechanism_illegitimate_binary++as.factor(data2$QQ1)+as.factor(data2$QQ2)+as.factor(data2$QQ3)+as.factor(data2$QQ4)+as.factor(data2$QQ5)) 
coef <- summary(regX)$coefficients[2]
se <- summary(regX)$coefficients[2,2]
smd_l <- coef-(1.645*se)
smd_u <- coef+(1.645*se)
coef<- coef*100
smd_l<- smd_l*100
smd_u<- smd_u*100

points(x=   n    , y=coef, pch=15,col=c1,lwd=7,cex=2)
segments(n , smd_l, n,smd_u, col=c1,lty=3,lwd=5)


## Treatment + No Demographics 
a <- 0.3
n <- b+a

regX <- lm(data3$consistency_binary ~ data3$mechanism_illegitimate_binary) 
coef <- summary(regX)$coefficients[2]
se <- summary(regX)$coefficients[4]
smd_l <- coef-(1.645*se)
smd_u <- coef+(1.645*se)
coef<- coef*100
smd_l<- smd_l*100
smd_u<- smd_u*100

points(x=   n    , y=coef, pch=19,col=c2,lwd=7)
segments(n , smd_l, n,smd_u, col=c2,lty=1,lwd=5)

## Treatment + Demographics 
a <- 0.4
n <- b+a

regX <- lm(data3$consistency_binary ~ data3$mechanism_illegitimate_binary++as.factor(data3$QQ1)+as.factor(data3$QQ2)+as.factor(data3$QQ3)+as.factor(data3$QQ4)+as.factor(data3$QQ5)) 
coef <- summary(regX)$coefficients[2]
se <- summary(regX)$coefficients[2,2]
smd_l <- coef-(1.645*se)
smd_u <- coef+(1.645*se)
coef<- coef*100
smd_l<- smd_l*100
smd_u<- smd_u*100

points(x=   n    , y=coef, pch=19,col=c2,lwd=7)
segments(n , smd_l, n,smd_u, col=c2,lty=3,lwd=5)




########## Change Needed #################

b <- 5.4

## Control + No Demographics 
a <- 0.0
n <- b+a

regX <- lm(data2$consistency_binary ~ data2$mechanism_changesneeded_binary) 
coef <- summary(regX)$coefficients[2]
se <- summary(regX)$coefficients[4]
smd_l <- coef-(1.645*se)
smd_u <- coef+(1.645*se)
coef<- coef*100
smd_l<- smd_l*100
smd_u<- smd_u*100

points(x=   n    , y=coef, pch=15,col=c1,lwd=7,cex=2)
segments(n , smd_l, n,smd_u, col=c1,lty=1,lwd=5)

## Control + Demographics 
a <- 0.1
n <- b+a

regX <- lm(data2$consistency_binary ~ data2$mechanism_changesneeded_binary++as.factor(data2$QQ1)+as.factor(data2$QQ2)+as.factor(data2$QQ3)+as.factor(data2$QQ4)+as.factor(data2$QQ5)) 
coef <- summary(regX)$coefficients[2]
se <- summary(regX)$coefficients[2,2]
smd_l <- coef-(1.645*se)
smd_u <- coef+(1.645*se)
coef<- coef*100
smd_l<- smd_l*100
smd_u<- smd_u*100

points(x=   n    , y=coef, pch=15,col=c1,lwd=7,cex=2)
segments(n , smd_l, n,smd_u, col=c1,lty=3,lwd=5)


## Treatment + No Demographics 
a <- 0.3
n <- b+a

regX <- lm(data3$consistency_binary ~ data3$mechanism_changesneeded_binary) 
coef <- summary(regX)$coefficients[2]
se <- summary(regX)$coefficients[4]
smd_l <- coef-(1.645*se)
smd_u <- coef+(1.645*se)
coef<- coef*100
smd_l<- smd_l*100
smd_u<- smd_u*100

points(x=   n    , y=coef, pch=19,col=c2,lwd=7)
segments(n , smd_l, n,smd_u, col=c2,lty=1,lwd=5)

## Treatment + Demographics 
a <- 0.4
n <- b+a

regX <- lm(data3$consistency_binary ~ data3$mechanism_changesneeded_binary++as.factor(data3$QQ1)+as.factor(data3$QQ2)+as.factor(data3$QQ3)+as.factor(data3$QQ4)+as.factor(data3$QQ5)) 
coef <- summary(regX)$coefficients[2]
se <- summary(regX)$coefficients[2,2]
smd_l <- coef-(1.645*se)
smd_u <- coef+(1.645*se)
coef<- coef*100
smd_l<- smd_l*100
smd_u<- smd_u*100

points(x=   n    , y=coef, pch=19,col=c2,lwd=7)
segments(n , smd_l, n,smd_u, col=c2,lty=3,lwd=5)




#####################################################################
######### Figure 8C: Consistency by Relavant Other Stuff	 ####
#####################################################################


data2 <- data[data$consistency_control %in% c(1),]
data3 <- data[data$consistency_treated %in% c(1),]

counts <- c(0,0,0,0,0)


par(mfrow=c(1,1),mar=c(4, 5, 3, 2),las=1)
barplot(counts,col=c("white"),names.arg=c("Drafing Process \n Has Been Succesful ","Intend to \n Vote for Adoption","Liberal \n Political Idology","Conservative \n Political Idology","High Constitutional \n Knowledge"),ylim=c(-19,45),ylab="Percentage Point Change",main="",axes=F)


y.axis <- c(-15,-10,-5,0,5,10,15,20,25,30,35,40,45)
Y <- c("-15","-10","-5","0","5","10","15","20","25","30","35","40","45")
axis(2,at = y.axis,labels=Y)


abline(h=0, col="black")
abline(h=-15, col="gray",lty=3)
abline(h=-10, col="gray",lty=3)
abline(h=-5, col="gray",lty=3)
abline(h=5, col="gray",lty=3)
abline(h=10, col="gray",lty=3)
abline(h=15, col="gray",lty=3)
abline(h=20, col="gray",lty=3)
abline(h=25, col="gray",lty=3)
abline(h=30, col="gray",lty=3)
abline(h=35, col="gray",lty=3)
abline(h=40, col="gray",lty=3)
abline(h=45, col="gray",lty=3)

segments(4.0 , 25, 7,25, col="white",lty=1,lwd=10)
segments(4.0 , 25, 7,25, col="white",lty=1,lwd=10)
segments(4.0 , 30, 7,30, col="white",lty=1,lwd=10)
segments(4.0 , 35, 7,35, col="white",lty=1,lwd=10)
segments(4.0 , 40, 7,40, col="white",lty=1,lwd=10)


#### Creating a Legend
points(x=   4.2    , y=40, pch=15,col=c1,lwd=2,cex=3)
segments(4.0 , 40, 4.4,40, col=c1,lty=1,lwd=2,cex=3)
text(4.7,40,"Control",cex=1.3)

points(x=   4.2    , y=35, pch=15,col=c1,lwd=2,cex=3)
segments(4.0 , 35, 4.4,35, col=c1,lty=3,lwd=2,cex=3)
text(5.25,35,"Control + Demographics",cex=1.3)

points(x=   4.2    , y=30, pch=19,col=c2,lwd=2,cex=3)
segments(4.0 , 30, 4.4,30, col=c2,lty=1,lwd=2,cex=3)
text(4.8,30,"Treatment",cex=1.3)

points(x=   4.2    , y=25, pch=19,col=c2,lwd=2,cex=3)
segments(4.0 , 25, 4.4,25, col=c2,lty=3,lwd=2,cex=3)
text(5.35,25,"Treatment + Demographics",cex=1.3)


#### Setting the Colors

c1 <-"aquamarine1"
c2 <-"indianred1"


########## Process #################

b <- 0.5

## Control + No Demographics 
a <- 0.0
n <- b+a

regX <- lm(data2$consistency_binary ~ data2$process) 
coef <- summary(regX)$coefficients[2]
se <- summary(regX)$coefficients[4]
smd_l <- coef-(1.645*se)
smd_u <- coef+(1.645*se)
coef<- coef*100
smd_l<- smd_l*100
smd_u<- smd_u*100

points(x=   n    , y=coef, pch=15,col=c1,lwd=7,cex=2)
segments(n , smd_l, n,smd_u, col=c1,lty=1,lwd=5)

## Control + Demographics 
a <- 0.1
n <- b+a

regX <- lm(data2$consistency_binary ~ data2$process++as.factor(data2$QQ1)+as.factor(data2$QQ2)+as.factor(data2$QQ3)+as.factor(data2$QQ4)+as.factor(data2$QQ5)) 
coef <- summary(regX)$coefficients[2]
se <- summary(regX)$coefficients[2,2]
smd_l <- coef-(1.645*se)
smd_u <- coef+(1.645*se)
coef<- coef*100
smd_l<- smd_l*100
smd_u<- smd_u*100

points(x=   n    , y=coef, pch=15,col=c1,lwd=7,cex=2)
segments(n , smd_l, n,smd_u, col=c1,lty=3,lwd=5)


## Treatment + No Demographics 
a <- 0.3
n <- b+a

regX <- lm(data3$consistency_binary ~ data3$process) 
coef <- summary(regX)$coefficients[2]
se <- summary(regX)$coefficients[4]
smd_l <- coef-(1.645*se)
smd_u <- coef+(1.645*se)
coef<- coef*100
smd_l<- smd_l*100
smd_u<- smd_u*100

points(x=   n    , y=coef, pch=19,col=c2,lwd=7)
segments(n , smd_l, n,smd_u, col=c2,lty=1,lwd=5)

## Treatment + Demographics 
a <- 0.4
n <- b+a

regX <- lm(data3$consistency_binary ~ data3$process++as.factor(data3$QQ1)+as.factor(data3$QQ2)+as.factor(data3$QQ3)+as.factor(data3$QQ4)+as.factor(data3$QQ5)) 
coef <- summary(regX)$coefficients[2]
se <- summary(regX)$coefficients[2,2]
smd_l <- coef-(1.645*se)
smd_u <- coef+(1.645*se)
coef<- coef*100
smd_l<- smd_l*100
smd_u<- smd_u*100

points(x=   n    , y=coef, pch=19,col=c2,lwd=7)
segments(n , smd_l, n,smd_u, col=c2,lty=3,lwd=5)


########## Vote #################

b <- 1.7

## Control + No Demographics 
a <- 0.0
n <- b+a

regX <- lm(data2$consistency_binary ~ data2$vote) 
coef <- summary(regX)$coefficients[2]
se <- summary(regX)$coefficients[4]
smd_l <- coef-(1.645*se)
smd_u <- coef+(1.645*se)
coef<- coef*100
smd_l<- smd_l*100
smd_u<- smd_u*100

points(x=   n    , y=coef, pch=15,col=c1,lwd=7,cex=2)
segments(n , smd_l, n,smd_u, col=c1,lty=1,lwd=5)

## Control + Demographics 
a <- 0.1
n <- b+a

regX <- lm(data2$consistency_binary ~ data2$vote++as.factor(data2$QQ1)+as.factor(data2$QQ2)+as.factor(data2$QQ3)+as.factor(data2$QQ4)+as.factor(data2$QQ5)) 
coef <- summary(regX)$coefficients[2]
se <- summary(regX)$coefficients[2,2]
smd_l <- coef-(1.645*se)
smd_u <- coef+(1.645*se)
coef<- coef*100
smd_l<- smd_l*100
smd_u<- smd_u*100

points(x=   n    , y=coef, pch=15,col=c1,lwd=7,cex=2)
segments(n , smd_l, n,smd_u, col=c1,lty=3,lwd=5)


## Treatment + No Demographics 
a <- 0.3
n <- b+a

regX <- lm(data3$consistency_binary ~ data3$vote) 
coef <- summary(regX)$coefficients[2]
se <- summary(regX)$coefficients[4]
smd_l <- coef-(1.645*se)
smd_u <- coef+(1.645*se)
coef<- coef*100
smd_l<- smd_l*100
smd_u<- smd_u*100

points(x=   n    , y=coef, pch=19,col=c2,lwd=7)
segments(n , smd_l, n,smd_u, col=c2,lty=1,lwd=5)

## Treatment + Demographics 
a <- 0.4
n <- b+a

regX <- lm(data3$consistency_binary ~ data3$vote++as.factor(data3$QQ1)+as.factor(data3$QQ2)+as.factor(data3$QQ3)+as.factor(data3$QQ4)+as.factor(data3$QQ5)) 
coef <- summary(regX)$coefficients[2]
se <- summary(regX)$coefficients[2,2]
smd_l <- coef-(1.645*se)
smd_u <- coef+(1.645*se)
coef<- coef*100
smd_l<- smd_l*100
smd_u<- smd_u*100

points(x=   n    , y=coef, pch=19,col=c2,lwd=7)
segments(n , smd_l, n,smd_u, col=c2,lty=3,lwd=5)




########## Liberal #################

b <- 2.9

## Control + No Demographics 
a <- 0.0
n <- b+a

regX <- lm(data2$consistency_binary ~ data2$liberal) 
coef <- summary(regX)$coefficients[2]
se <- summary(regX)$coefficients[4]
smd_l <- coef-(1.645*se)
smd_u <- coef+(1.645*se)
coef<- coef*100
smd_l<- smd_l*100
smd_u<- smd_u*100

points(x=   n    , y=coef, pch=15,col=c1,lwd=7,cex=2)
segments(n , smd_l, n,smd_u, col=c1,lty=1,lwd=5)

## Control + Demographics 
a <- 0.1
n <- b+a

regX <- lm(data2$consistency_binary ~ data2$liberal++as.factor(data2$QQ1)+as.factor(data2$QQ2)+as.factor(data2$QQ3)+as.factor(data2$QQ4)) 
coef <- summary(regX)$coefficients[2]
se <- summary(regX)$coefficients[2,2]
smd_l <- coef-(1.645*se)
smd_u <- coef+(1.645*se)
coef<- coef*100
smd_l<- smd_l*100
smd_u<- smd_u*100

points(x=   n    , y=coef, pch=15,col=c1,lwd=7,cex=2)
segments(n , smd_l, n,smd_u, col=c1,lty=3,lwd=5)


## Treatment + No Demographics 
a <- 0.3
n <- b+a

regX <- lm(data3$consistency_binary ~ data3$liberal) 
coef <- summary(regX)$coefficients[2]
se <- summary(regX)$coefficients[4]
smd_l <- coef-(1.645*se)
smd_u <- coef+(1.645*se)
coef<- coef*100
smd_l<- smd_l*100
smd_u<- smd_u*100

points(x=   n    , y=coef, pch=19,col=c2,lwd=7)
segments(n , smd_l, n,smd_u, col=c2,lty=1,lwd=5)

## Treatment + Demographics 
a <- 0.4
n <- b+a

regX <- lm(data3$consistency_binary ~ data3$liberal++as.factor(data3$QQ1)+as.factor(data3$QQ2)+as.factor(data3$QQ3)+as.factor(data3$QQ4)) 
coef <- summary(regX)$coefficients[2]
se <- summary(regX)$coefficients[2,2]
smd_l <- coef-(1.645*se)
smd_u <- coef+(1.645*se)
coef<- coef*100
smd_l<- smd_l*100
smd_u<- smd_u*100

points(x=   n    , y=coef, pch=19,col=c2,lwd=7)
segments(n , smd_l, n,smd_u, col=c2,lty=3,lwd=5)



########## Convervative #################

b <- 4.2

## Control + No Demographics 
a <- 0.0
n <- b+a

regX <- lm(data2$consistency_binary ~ data2$conservative) 
coef <- summary(regX)$coefficients[2]
se <- summary(regX)$coefficients[4]
smd_l <- coef-(1.645*se)
smd_u <- coef+(1.645*se)
coef<- coef*100
smd_l<- smd_l*100
smd_u<- smd_u*100

points(x=   n    , y=coef, pch=15,col=c1,lwd=7,cex=2)
segments(n , smd_l, n,smd_u, col=c1,lty=1,lwd=5)

## Control + Demographics 
a <- 0.1
n <- b+a

regX <- lm(data2$consistency_binary ~ data2$conservative++as.factor(data2$QQ1)+as.factor(data2$QQ2)+as.factor(data2$QQ3)+as.factor(data2$QQ4)) 
coef <- summary(regX)$coefficients[2]
se <- summary(regX)$coefficients[2,2]
smd_l <- coef-(1.645*se)
smd_u <- coef+(1.645*se)
coef<- coef*100
smd_l<- smd_l*100
smd_u<- smd_u*100

points(x=   n    , y=coef, pch=15,col=c1,lwd=7,cex=2)
segments(n , smd_l, n,smd_u, col=c1,lty=3,lwd=5)


## Treatment + No Demographics 
a <- 0.3
n <- b+a

regX <- lm(data3$consistency_binary ~ data3$conservative) 
coef <- summary(regX)$coefficients[2]
se <- summary(regX)$coefficients[4]
smd_l <- coef-(1.645*se)
smd_u <- coef+(1.645*se)
coef<- coef*100
smd_l<- smd_l*100
smd_u<- smd_u*100

points(x=   n    , y=coef, pch=19,col=c2,lwd=7)
segments(n , smd_l, n,smd_u, col=c2,lty=1,lwd=5)

## Treatment + Demographics 
a <- 0.4
n <- b+a

regX <- lm(data3$consistency_binary ~ data3$conservative++as.factor(data3$QQ1)+as.factor(data3$QQ2)+as.factor(data3$QQ3)+as.factor(data3$QQ4)) 
coef <- summary(regX)$coefficients[2]
se <- summary(regX)$coefficients[2,2]
smd_l <- coef-(1.645*se)
smd_u <- coef+(1.645*se)
coef<- coef*100
smd_l<- smd_l*100
smd_u<- smd_u*100

points(x=   n    , y=coef, pch=19,col=c2,lwd=7)
segments(n , smd_l, n,smd_u, col=c2,lty=3,lwd=5)




########## Knoweldge #################

b <- 5.4

## Control + No Demographics 
a <- 0.0
n <- b+a

regX <- lm(data2$consistency_binary ~ data2$know) 
coef <- summary(regX)$coefficients[2]
se <- summary(regX)$coefficients[4]
smd_l <- coef-(1.645*se)
smd_u <- coef+(1.645*se)
coef<- coef*100
smd_l<- smd_l*100
smd_u<- smd_u*100

points(x=   n    , y=coef, pch=15,col=c1,lwd=7,cex=2)
segments(n , smd_l, n,smd_u, col=c1,lty=1,lwd=5)

## Control + Demographics 
a <- 0.1
n <- b+a

regX <- lm(data2$consistency_binary ~ data2$know++as.factor(data2$QQ1)+as.factor(data2$QQ2)+as.factor(data2$QQ3)+as.factor(data2$QQ4)+as.factor(data2$QQ5)) 
coef <- summary(regX)$coefficients[2]
se <- summary(regX)$coefficients[2,2]
smd_l <- coef-(1.645*se)
smd_u <- coef+(1.645*se)
coef<- coef*100
smd_l<- smd_l*100
smd_u<- smd_u*100

points(x=   n    , y=coef, pch=15,col=c1,lwd=7,cex=2)
segments(n , smd_l, n,smd_u, col=c1,lty=3,lwd=5)


## Treatment + No Demographics 
a <- 0.3
n <- b+a

regX <- lm(data3$consistency_binary ~ data3$know) 
coef <- summary(regX)$coefficients[2]
se <- summary(regX)$coefficients[4]
smd_l <- coef-(1.645*se)
smd_u <- coef+(1.645*se)
coef<- coef*100
smd_l<- smd_l*100
smd_u<- smd_u*100

points(x=   n    , y=coef, pch=19,col=c2,lwd=7)
segments(n , smd_l, n,smd_u, col=c2,lty=1,lwd=5)

## Treatment + Demographics 
a <- 0.4
n <- b+a

regX <- lm(data3$consistency_binary ~ data3$know++as.factor(data3$QQ1)+as.factor(data3$QQ2)+as.factor(data3$QQ3)+as.factor(data3$QQ4)+as.factor(data3$QQ5)) 
coef <- summary(regX)$coefficients[2]
se <- summary(regX)$coefficients[2,2]
smd_l <- coef-(1.645*se)
smd_u <- coef+(1.645*se)
coef<- coef*100
smd_l<- smd_l*100
smd_u<- smd_u*100

points(x=   n    , y=coef, pch=19,col=c2,lwd=7)
segments(n , smd_l, n,smd_u, col=c2,lty=3,lwd=5)




##########################################################################################
######### Save for Stata to Run Regressions for Appendix 3			   ####
##########################################################################################

## Support Process
data$process<-0
data$process[data$QB3 %in% c(1,2)]<-1

## Intend to Vote
data$vote<-0
data$vote[data$QB4 %in% c(1,2)]<-1

table(data$QB3)

## Liberal 
data$liberal<-0
data$liberal[data$QQ5 %in% c(1,2,3)]<-1

## Convervative
data$conservative<-0
data$conservative[data$QQ5 %in% c(8,9,10)]<-1

## Constitutional Knowledge
data$know<-0
data$know[data$QL2==3 & data$QL3==2 & data$QL4 ==4]<-1


names(data)

keeps <- c("consistency_binary","substance_binding_binary","substance_good_binary","substance_strikedown_binary","substance_votedown_binary","mechanism_legal_binary","mechanism_gradual_binary","mechanism_minority_binary","mechanism_illegitimate_binary","mechanism_changesneeded_binary","process","vote","know","conservative","liberal","QQ1","QQ2","QQ3","QQ4","QQ5_1","consistency_treated","consistency_control")
data = data[keeps]
write.dta(data,"Data_ChileSurvey_Appendix3_230313.dta")





